// 1.包含头文件
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

// 3.自定义节点类；
class Arm_Control : public rclcpp::Node
{
public:
    Arm_Control() : Node("arm_control_node_cpp")
    {
        action_pub = this->create_publisher<std_msgs::msg::Int32>("arm_action", 5);
        action_type1();
    }

private:
    // 动作发布方
    rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr action_pub;

    void action_type1()
    {
        auto action_flag = std_msgs::msg::Int32();
        action_flag.data = 3;
        action_pub->publish(action_flag);
        delay_ms(1000);
        action_flag.data = 2;
        action_pub->publish(action_flag);
        delay_ms(1000);
        action_flag.data = 4;
        action_pub->publish(action_flag);
        delay_ms(1000);
    }
    // 延时毫秒函数
    void delay_ms(int milliseconds)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
    }
};

int main(int argc, char const *argv[])
{
    // 2.初始化ROS2客户端；
    rclcpp::init(argc, argv);
    // 4.调用spain函数，并传入节点对象指针；
    rclcpp::spin(std::make_shared<Arm_Control>());
    // 5.资源释放
    rclcpp::shutdown();
    return 0;
}